# -*- coding:utf-8 -*-

import requests
import urllib
import json


def startTask():

	#拉取任务
	url = 'http://qianggou.hooioo.com/index.php/Rpc/startTaskRel'
	Head={ 'User-Agent':'FLASHSALE',
		   'Referer': 'http://store.nike.com/cn/zh_cn/',
		   'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
		   'X-Requested-With':'XMLHttpRequest'}

	data = urllib.urlencode({'tid':'2'})
	resp = requests.post(url,headers=Head,data=data)
	try:
		task_relid = resp.json()['data'][0]['task_relid']
		print task_relid
		#开启任务
		url = 'http://qianggou.hooioo.com/index.php/Rpc/taskdetails'
		data = urllib.urlencode({'taskrelid':task_relid,'tid':'2'})
		resp = requests.post(url,headers=Head,data=data)
		print resp.text

		#开启任务
		url = 'http://qianggou.hooioo.com/index.php/Rpc/upTaskStatus'
		data = urllib.urlencode({'taskrelid':task_relid,'tid':'2'})
		resp = requests.post(url,headers=Head,data=data)
		print resp.text

	except:
		print 'please add flashsale task'





#开启任务	
startTask()